<?php
/**
 * 后台主页控制器
 * User: xuyiping(xuyiping@liangzihuzhu.com)
 * Date: 2017/12/1
 * Time: 14:44
 */

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\DB;
use Symfony\Component\HttpFoundation\Request;
class UserController extends Controller
{


    public function exChangeGold($p,$user,$type){
        //1 add  2  reduce 3 兑换 4 sign签到

        $update = array();
        $update['dtModifyTime'] = date("Y-m-d H:i:s");
        $update['sModifyUser']  = $user;
        if($p > 0){
            //金豆总表
            //$update['iAllGoldBean']='iAllGoldBe'.$p;
            $num = DB::table('goldbean')
                ->where("iUserID",'=',$user)
                ->increment('iNowGoldBean',$p,$update);
            $num = DB::table('goldbean')
                ->where("iUserID",'=',$user)
                ->increment('iAllGoldBean',$p);
        }else{
            $num = DB::table('goldbean')
                ->where("iUserID",'=',$user)
                ->increment('iNowGoldBean',$p,$update);
        }
        //金豆流水表
        $adddata = array();
        $adddata['iUserId']          = $user;
        $adddata['iGoldBeanConsume'] = $p;
        $adddata['iConsumeType']     = $type;
        $adddata['dtModifyTime']     = date("Y-m-d H:i:s");
        $adddata['sModifyUser']      = $user;

        $num = DB::table('goldrecord')
            ->where("iUserID",'=',$user)
            ->insertGetId($adddata);

        return response()->json(array(
            'code' => 200,
            'message'=> '操作成功！！！',
        ));
    }

}